package ${controller.packagePath};

<#list controller.packages as pkg>
<#if pkg?has_content>
import ${pkg};
<#else>

</#if>
</#list>

/**
 * <p>
 * ${tableComment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@RestController
@RequestMapping("/${moduleName}/${controller.url}")
@ResponseResultVo
@Tag(name = "${tableComment!} 管理")
public class ${controller.className} {

    @Resource
    private ${service.className} ${service.className?uncap_first};
    <#if genPage>

    @GetMapping("/page")
    @SaCheckPermission("${moduleName}:${controller.url}:list")
    @Operation(summary = "${tableComment!} 分页查询")
    public IPage<${pageResult.className}> page(@ParameterObject ${pageParam.className} param) {
        return ${service.className?uncap_first}.page(param);
    }
    </#if>
    <#if genInfo>

    @GetMapping("/info/{id}")
    @SaCheckPermission("${moduleName}:${controller.url}:info")
    @Operation(summary = "${tableComment!} 信息")
    public ${infoResult.className} info(@PathVariable("id") @Parameter(name = "id", description = "${tableComment!} id") ${pkType} id) {
        return ${service.className?uncap_first}.info(id);
    }
    </#if>
    <#if genSave>

    @PostMapping("/save")
    @SaCheckPermission("${moduleName}:${controller.url}:save")
    @Operation(summary = "${tableComment!} 新增")
    public void save(@RequestBody @Validated ${saveParam.className} param) {
        ${service.className?uncap_first}.save(param);
    }
    </#if>
    <#if genUpdate>

    @PostMapping("/update")
    @SaCheckPermission("${moduleName}:${controller.url}:update")
    @Operation(summary = "${tableComment!} 更新")
    public void update(@RequestBody @Validated ${updateParam.className} param) {
        ${service.className?uncap_first}.update(param);
    }
    </#if>
    <#if genDeleted>

    @PostMapping("/delete")
    @SaCheckPermission("${moduleName}:${controller.url}:delete")
    @Operation(summary = "${tableComment!} 删除")
    public void delete(@RequestBody List<${pkType}> ids) {
        ${service.className?uncap_first}.delete(ids);
    }
    </#if>
    <#if genImport>

    @PostMapping("/import/excel")
    @SaCheckPermission("${moduleName}:${controller.url}:import")
    @Operation(summary = "${tableComment!} excel导入")
    public void importExcel(@Parameter(description = "导入excel文件") @RequestParam("file") MultipartFile file) throws IOException {
        ${service.className?uncap_first}.importExcel(file.getInputStream());
    }

    @GetMapping("/import/template")
    @SaCheckPermission("${moduleName}:${controller.url}:import")
    @Operation(summary = "${tableComment!} excel导入模板")
    public void importTemplate() throws IOException {
        ServletUtil.download("${tableComment!}-导入模板.xlsx",
                outputStream -> ${service.className?uncap_first}.importExcelTemplate(outputStream));
    }
    </#if>
    <#if genExport>

    @GetMapping("/export/excel")
    @SaCheckPermission("${moduleName}:${controller.url}:export")
    @Operation(summary = "${tableComment!} excel导出")
    public void exportExcel(@ParameterObject ${pageParam.className} param) throws IOException {
        ServletUtil.download("${tableComment!}-导出数据.xlsx",
                outputStream -> ${service.className?uncap_first}.exportExcel(param, outputStream));
    }
    </#if>

}

